package main;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.EmptyBorder;

public class NoPhones extends JFrame {

	private JPanel contentPane;
	static String user = "root";
	static String pass = "";
	static String url = "jdbc:mysql://localhost:3306/qlsodt";
	public static Connection con;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					NoPhones frame = new NoPhones();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @throws Exception 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 */
	public NoPhones() throws Exception {
		try {
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			con = DriverManager.getConnection(url, user, pass);
			System.out.print("Connected");

		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.print("Not connect");
		}
		setBounds(200, 50, 229, 427);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		DefaultListModel<String> model = new DefaultListModel<>();

		String s = "select * from socosan";
		Statement st = con.createStatement();
		st.executeQuery(s);
		ResultSet rs = st.getResultSet();
		while (rs.next()) {
			model.addElement(rs.getString("NoPhone"));
		}
		JList listNo = new JList(model);

		JScrollPane scrollPane = new JScrollPane(listNo);
		scrollPane.setBounds(10, 40, 200, 300);

		Container contentPane = getContentPane();
		getContentPane().setLayout(null);
		contentPane.add(scrollPane);

		JButton btnng = new JButton("Đóng");
		btnng.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dispose();
			}
		});
		btnng.setBounds(63, 345, 89, 23);
		getContentPane().add(btnng);

		JLabel lblCcS = new JLabel("Các số mới chưa đăng ký:");
		lblCcS.setForeground(Color.RED);
		lblCcS.setFont(new Font("Tahoma", Font.BOLD, 12));
		lblCcS.setBounds(10, 11, 185, 14);
		getContentPane().add(lblCcS);
	}

}
